//
//  NSString+HXBase64.m
//  24_加密
//
//  Created by 徐昊 on 16/8/16.
//  Copyright © 2016年 徐昊. All rights reserved.
//

#import "NSString+HXBase64.h"

@implementation NSString (HXBase64)
- (NSString *)stringWithBase64 {
    // 把字符串转成NSData
    NSData *stringData = [self dataUsingEncoding:NSUTF8StringEncoding];
    // 根据NSData, 生成Base64字符串
    NSString *base64String = [stringData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    return base64String;
}
- (NSString *)base64WithString {
    // 根据Base64字符串, 生成NSData
    NSData *base64Data = [[NSData alloc] initWithBase64EncodedString:self options:NSDataBase64DecodingIgnoreUnknownCharacters];
    // 把NSData转成字符串
    NSString *originString = [[NSString alloc] initWithData:base64Data encoding:NSUTF8StringEncoding];
    return originString;
}
@end
